/**
 * 银行卡表管理初始化
 */
var UsersBankcards = {
    id: "UsersBankcardsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
UsersBankcards.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '', field: 'bankCardId', visible: true, align: 'center', valign: 'middle',formatter:function (value,row,index) {
                    return index+1;
                }},
            {title: '用户姓名', field: 'userName', visible: true, align: 'center', valign: 'middle'},
            {title: '开户行', field: 'accArea', visible: true, align: 'center', valign: 'middle'},
            {title: '银行卡号', field: 'accNo', visible: true, align: 'center', valign: 'middle'},
            {title: '银行预留手机号码', field: 'phone', visible: true, align: 'center', valign: 'middle'},
            {title: '是否是默认银行卡', field: 'type', visible: true, align: 'center', valign: 'middle',formatter:UsersBankcards.showType},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
            {title: '操作', field: 'op', visible: true, align: 'center', valign: 'middle',formatter:UsersBankcards.op}
    ];
};

//1默认 2不是
UsersBankcards.showType = function(value,row,index){
    var result = '';
    switch (value) {
        case 1:
            result = '默认';
            break;
        case 2:
            result = '不是';
            break;
        default:
            break;
    }
    return result;
};

UsersBankcards.op = function(value,row,index){
    return "<a href='javascript:void(0)' onclick='UsersBankcards.openUsersBankcardsDetail()'>详情</a>";
};
/**
 * 检查是否选中
 */
UsersBankcards.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        UsersBankcards.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加银行卡表
 */
UsersBankcards.openAddUsersBankcards = function () {
    var index = layer.open({
        type: 2,
        title: '添加银行卡表',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/usersBankcards/usersBankcards_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看银行卡表详情
 */
UsersBankcards.openUsersBankcardsEdit = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '银行卡表编辑',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/usersBankcards/usersBankcards_update/' + UsersBankcards.seItem.bankCardId
        });
        this.layerIndex = index;
    }
};

/**
 * 打开查看银行卡表详情
 */
UsersBankcards.openUsersBankcardsDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '银行卡表详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/usersBankcards/usersBankcards_info/' + UsersBankcards.seItem.bankCardId
        });
        this.layerIndex = index;
    }
};

/**
 * 删除银行卡表
 */
UsersBankcards.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/usersBankcards/delete", function (data) {
            Feng.success("删除成功!");
            UsersBankcards.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("usersBankcardsId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询银行卡表列表
 */
UsersBankcards.search = function () {
    var queryData = {};
    queryData['accNo'] = $("#accNo").val();
    queryData['phone'] = $("#phone").val();
    queryData['userName'] = $("#userName").val();
    UsersBankcards.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = UsersBankcards.initColumn();
    var table = new BSTable(UsersBankcards.id, "/usersBankcards/list", defaultColunms);
    table.setPaginationType("client");
    UsersBankcards.table = table.init();
});
